<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
   



         
        <script>

             
              /*
                1.原型链继承  复杂数据会出现数据污染的情景
            
                function Person(name){
                        this.name=name
                        this.eats=['苹果','香蕉']
                }
                Person.prototype.fm=function(){
                    console.log(this.name)

                }
                function PersonChil(){
                    
                }
                PersonChil.prototype=new Person('xiaoming')
                let p1=new PersonChil()
                p1.eats.push('哈密瓜')
                let p2=new PersonChil()
                console.log(p1)   
                console.log(p2)  
                   */  

              /*
                构造函数继承
                 没法继承原型链上的属性和方法
              
               function Person(name){
                        this.name=name
                        this.eats=['苹果','香蕉']
                }
                Person.prototype.fm=function(){
                    console.log(this.name)

                }
                function PersonChil(name){
                    Person.call(this,name)
                }
                
                let p1=new PersonChil('xiaoming')
                p1.eats.push('哈密瓜')
                let p2=new PersonChil('xiaohong')
                console.log(p1)   
                console.log(p2) 
                 */ 
                 /*
                    Person实例化了2次
                

                 function Person(name){
                        this.name=name
                        this.eats=['苹果','香蕉']
                }
                Person.prototype.fm=function(){
                    console.log(this.name)

                }
                function PersonChil(name){
                    Person.call(this,name) //1
                }
                PersonChil.prototype=new Person()//2
                let p1=new PersonChil('xiaoming')
                p1.eats.push('哈密瓜')
                let p2=new PersonChil('xiaohong')
                console.log(p1)   
                console.log(p2) 

                 */

                 /*
                    继生组合继承
                 */

                 function Person(name){
                        this.name=name
                        this.eats=['苹果','香蕉']
                }
                Person.prototype.fm=function(){
                    console.log(this.name)

                }
                function PersonChil(name){
                    Person.call(this,name) 
                }
                // PersonChil.prototype=new Person()
                PersonChil.prototype=Object.create(Person.prototype)  

                let p1=new PersonChil('xiaoming')
                p1.eats.push('哈密瓜')
                let p2=new PersonChil('xiaohong')
                console.log(p1)   
                console.log(p2) 
              
               

                
                

             









        </script>

      
</body>
</html>